home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5186 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  83 lines

  1. Path: hdxx05.telecom.ptt.nl!usenet
  2. From: A.B.deVries@PTT-Telecom.NL (Fred de Vries)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Newbie Q: Arrays > 64K take 2
  5. Date: 8 Feb 1996 11:39:38 GMT
  6. Organization: PTT Telecom B.V.
  7. Message-ID: <4fcndq$1pl@hdxx05.telecom.ptt.nl>
  8. References: <4f5k8p$dg4@earth.superlink.net>
  9. NNTP-Posting-Host: 138.204.177.15
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <4f5k8p$dg4@earth.superlink.net>, rizzom@mars.superlink.net says...
  15. >
  16. >Hi,
  17. >   
  18. >   I'm using Turbo C++ (compliing in C) with DOS.  I am having 
  19. >trouble with an arrya larger than 64K.  I keep getting the 
  20. >error:  Array too large.  I have tried the medium, compact, 
  21. >large, and huge memory models but they did not work.  Here is 
  22. >the definition of the struture and declaration of the array:
  23. >
  24. >typedef enum {IDLE = 0, BUSY = 1} proc_state;
  25. >
  26. >typedef struct
  27. >       {
  28. >       char inst[10];
  29. >       }InstString;
  30. >
  31. >typedef struct
  32. >       {
  33. >       int datamem[102];
  34. >       InstString instruct[102];
  35. >       proc_state state;
  36. >       int PC;
  37. >       char IR[10];
  38. >       int AC;
  39. >       }VMProc;
  40. >
  41. >main()
  42. >{
  43. >VMProc proc[64];
  44. >..
  45. >}
  46.  
  47. Try something like:
  48.  
  49. main()
  50. {
  51.    VMProc  *proc[64];
  52.    int      ndx;
  53.  
  54.    ...
  55.    for (ndx=0; ndx<64; ndx++)
  56.       proc[ndx] = (VMProc *)malloc(sizeof VMProc);
  57.    ...
  58. }
  59.  
  60. Now each element is seperatly allocated, so no problems with
  61. segment sizes/boundaries.
  62.  
  63. Just keep in mind that:
  64.   a)  proc[n] is a POINTER to a structure, NOT a structure 
  65.       by itself!!!
  66.   b)  Check the returnvalue of malloc() to be sure you really
  67.       did get some memory!
  68.  
  69.  
  70. Hope this helps
  71.  
  72. ----------------------------------------------------------------------------
  73. Fred de Vries             | Telephone: +31 70 3432511
  74. PTT Telecom BV            | Telefax  : +31 70 3436393
  75. I&AT TU B&O               | E-mail   : A.B.deVries@PTT-Telecom.NL
  76. P.O. 423                  | X.400    : C=NL  A=400NET  O=DLC 
  77. NL-2260 AK Leidschendam   |            S=De Vries G=Fred
  78. The Netherlands           |  
  79. DISCLAIMER: This statement is not an official statement from, nor 
  80.             does it represent an official position of, PTT Telecom B.V.
  81. ----------------------------------------------------------------------------
  82.  
  83.